<template>
  <drag-modal
    title="查看"
    :width="500"
    :visible="visible"
    :destroyOnClose="true"
    :maskClosable="false"
    @cancel="cancel"
  >
    <a-spin :spinning="loading">
      <div style="max-height: 500px; overflow-y: auto;">
        <a-form-model :model="form" ref="form"  :label-col="{span: 5}" :wrapperCol="{span: 16, offset: 1}">
          <div class="fold">
            <a-form-model-item
              label="上级菜单"
              prop="parentName"
            >
              <span>{{form.parentName}}</span>
            </a-form-model-item>
            <a-form-model-item
              label="菜单类型"
              prop="type"
            >
              <span>{{form.type | dictFilter(dict.type)}}</span>
            </a-form-model-item>
            <a-form-model-item
              label="菜单名称"
              prop="name"
            >
              <span>{{form.name}}</span>
            </a-form-model-item>
            <a-form-model-item
              v-if="form.type != 2"
              label="菜单标识"
              prop="code"
            >
              <span>{{form.code}}</span>
            </a-form-model-item>
            <a-form-model-item
              v-if="form.type != 2"
              label="路由地址"
              prop="path"
            >
              <span>{{form.path}}</span>
            </a-form-model-item>
            <a-form-model-item
              label="权限标识"
              prop="permission"
            >
              <span>{{form.permission}}</span>
            </a-form-model-item>
            <a-form-model-item
              v-if="form.type != 2"
              label="组件路径"
              prop="component"
            >
              <span>{{form.component}}</span>
            </a-form-model-item>
<!--            <a-form-model-item
              v-if="form.type == 1"
              label="外链地址"
              prop="href"
            >
              <span>{{form.href}}</span>
            </a-form-model-item> -->
            <a-form-model-item
              v-if="form.type == 1"
              label="外链地址"
              prop="link"
            >
              <span>{{form.link}}</span>
            </a-form-model-item>
            <a-form-model-item
              v-if="form.type != 2"
              label="图标"
              prop="icon"
            >
              <span>{{form.icon}}</span>
            </a-form-model-item>
            <a-form-model-item
              label="排序"
              prop="sort"
            >
              <span>{{form.sort}}</span>
            </a-form-model-item>
            <a-form-model-item
              v-if="form.type != 2"
              label="是否隐藏"
              prop="invisible"
            >
              <span>{{form.status | dictFilter(dict.yesOrNo)}}</span>
            </a-form-model-item>
            <a-form-model-item
              v-if="form.type == 1"
              label="不可关闭"
              prop="closable"
            >
              <span>{{form.status | dictFilter(dict.yesOrNo)}}</span>
            </a-form-model-item>
            <a-form-model-item
              label="系统菜单"
              prop="isSystem"
            >
              <span>{{form.status | dictFilter(dict.yesOrNo)}}</span>
            </a-form-model-item>
            <a-form-model-item
              label="状态"
              prop="status"
            >
              <span>{{form.status | dictFilter(dict.yesOrNo)}}</span>
            </a-form-model-item>
          </div>
        </a-form-model>
      </div>
    </a-spin>
    <template slot="footer">
      <a-button @click="cancel">关闭</a-button>
    </template>
  </drag-modal>
</template>

<script>
import {menuService} from '@/services'
 
export default {
  name: 'QueryModal',
  props: {
    visible: {
      type: Boolean,
      required: true
    }
  },
  data () {
    return {
      loading: false,
      parentTreeData: [],
      form: {
        type: undefined,
        parentId: undefined,
        parentName: undefined,
        name: undefined,
        path: undefined,
        code: undefined,
        permission: undefined,
        component: undefined,
        link: undefined,
        href: undefined,
        icon: undefined,
        sort: undefined,
        status: undefined,
        invisible: undefined,
        closable: undefined,
        isSystem: undefined
      },
      dict: {
        type: [],
        status: [],
        yesOrNo: []
      }
    }
  },
  filters: {
    dictFilter: (val, dictList) => {
      const dict = dictList.find(item => item.value == val)
      return dict ? dict.title : '未知'
    }
  },
  methods: {
    cancel() {
      this.$emit('cancel')
    },
    queryAction(val) {
      this.loading = true
      const params = {
        id: val
      }
      menuService.query(JSON.stringify(params)).then(res => {
        const result = res.data
        if (result.code === 200) {
          this.form = result.data
        }
      }).finally(this.loading = false)
    },
    queryParentAction() {
      this.loading = true
      menuService.queryParentTree().then(res => {
        const result = res.data
        if (result.code === 200) {
          this.parentTreeData = result.data
        }
      }).finally(this.loading = false)
    }
  },
  mounted() {
    this.getDict(JSON.stringify({code: 'SYS_MENU_TYPE'})).then(res => this.dict.type = res.data.data)
    this.getDict(JSON.stringify({code: 'SYS_STATUS'})).then(res => this.dict.status = res.data.data)
    this.getDict(JSON.stringify({code: 'SYS_YES_OR_NO'})).then(res => this.dict.yesOrNo = res.data.data)
  }
}
</script>
